Page({
  data: {
    searchValue: '',
    departments: [
      '消化内科',
      '普通内科',
      '呼吸内科',
      '神经科',
      '心血管内科',
      '内分泌科',
      '肾病内科',
      '血液科',
      '风湿科',
      '感染性疾病科'
    ],
    filteredDepartments: []
  },

  onLoad() {
    // 初始化显示所有科室
    this.setData({
      filteredDepartments: this.data.departments
    });
  },

  onSearchChange(e) {
    const searchValue = e.detail;
    this.setData({
      searchValue
    });
    
    // 根据搜索值筛选科室
    const filteredDepartments = this.data.departments.filter(dept => 
      dept.toLowerCase().includes(searchValue.toLowerCase())
    );
    
    this.setData({
      filteredDepartments
    });
  },

  selectDepartment(e) {
    const department = e.currentTarget.dataset.department;
    // 删除存储选择的科室
    // wx.setStorageSync('selectedDepartment', department);
    
    // 返回上一页并更新数据
    const pages = getCurrentPages();
    const prevPage = pages[pages.length - 2];
    prevPage.setData({
      department: department
    });
    
    wx.navigateBack();
  }
}); 